package org.jeecg.modules.user.home.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.modules.user.home.dto.StationNameReq;
import org.jeecg.modules.user.home.service.AppHomeService;
import org.jeecg.modules.utils.BikeResult;
import org.jeecg.modules.utils.DistanceUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.text.DecimalFormat;


@Validated
@RestController
@RequestMapping("/app/home")
@Api(tags = "app首页")
public class AppHomePageController {

    @Autowired
    private AppHomeService appHomeService;

    @ApiOperation(value = "app首页", notes = "app首页")
    @RequestMapping(value = "/getAppHomePageList", method = RequestMethod.POST)
    public BikeResult getAppHomePageList(@RequestBody StationNameReq stationNameReq){
        return appHomeService.getAppHomePageList(stationNameReq);
    }

//    @ApiOperation(value = "查询站点", notes = "查询站点")
//    @RequestMapping(value = "/getbikeStationList", method = RequestMethod.GET)
//    public ItzResult getbikeStationList(String name){
//        return appHomeService.getbikeStationList(name);
//    }


    @ApiOperation(value = "测试距离", notes = "app首页")
    @RequestMapping(value = "/testDistance", method = RequestMethod.POST)
    public BikeResult testDistance(double lo1,double la1,double lo2,double la2){
        double[] doubles = DistanceUtils.GCJ02ToWGS84(lo1, la1);
        double distance = DistanceUtils.getDistance(doubles[0], doubles[1], lo2, la2);
        String format = new DecimalFormat("0.0").format(distance);
        return BikeResult.ok(format) ;
    }

    @ApiOperation(value = "app骑行费用说明", notes = "app首页")
    @RequestMapping(value = "/getCostsThat", method = RequestMethod.GET)
    public BikeResult getCostsThat(){
        String test = "0元/120分钟，第3小时收费1元(不足1小时按1小时计)\n" +
                "第4小时及以上每小时收费3元(不足1小时按1小时计)";
        return BikeResult.ok("1", "查询成功", test);

    }
}
